package com.lyf.shop.config;

import com.lyf.shop.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * MVC配置
 */
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Title: WebMvcConfig
 * @Description:
 * @Authen: lwj
 * @Version: 1.0
 * @Create: 2021/12/2 14:25
 */
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Title: WebMvcConfig
 * @Description:
 * @Authen: lwj
 * @Version: 1.0
 * @Create: 2021/12/2 14:25
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    /**
     * 用于保存服务静态资源图片,css文件或者其他文件的资源处理器(resource handler)的注册信息
     * */
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/images/**").addResourceLocations("file:D:\\springboot\\shop_lyf\\src\\main\\webapp\\images\\");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**")
                .excludePathPatterns("/jsp/login.jsp","/user/*","/admin.jsp","/jsp/index.jsp","/css/*","/images/*"
                        ,"/img/*","/image/*","/imgs/*","/js/*","/jss/*","/jsp/register.jsp","/user/addUser","/product/allBook");
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/index_article").setViewName("jsp/index_article");
    }
}
